package com.sl.au.repository;


import com.sl.au.entity.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface TaskRepository extends JpaRepository<Task, String> {
	
//////首页待处理信息获取数据//////
  @Query( "select t from Task t where transactorId=?1 or transactorId=?2")
	Page<Task> getMyTask(String userId,String roleId,Pageable pageable);
	
  @Query( "select count(*) from Task t where transactorId=?1 or transactorId=?2")
	long getTaskCount(String userId,String roleId);
  
  Task findByUndoTaskIdAndName(String taskId,String name);
  
  
	/**
	 * 获取待处理的员工跟踪数据
	 */
	@Query( "select c from ChanceManagerDelivery c where c.user.id =?1 and isReceived = 0 "
			+ "and c.saleChance.closeReason = null")
	Page<ChanceManagerDelivery> getChanceTrances(String userId,Pageable pageable);
	/**
	 * 获取待处理的信息分配（经理）数据
	 */
	@Query( "select c from ChanceDelivery c where c.saleArea.id =?1 and isReceived = 0"
			+ "and c.saleChance.closeReason = null")
	Page<ChanceDelivery> getChanceManagerDeliverys(String areaId,Pageable pageable);
	/**
	 * 获取待处理的信息分配（处长）数据
	 */
	@Query( "select c from ChanceDeliveryTemp c where c.receiveSuperior =?1 and isReceived = 0"
			+ "and c.saleChance.closeReason = null")
	Page<ChanceDeliveryTemp> getChanceDeliverys(String superior,Pageable pageable);
	
	/**
	 * 获取待处理的信息分配（科长）数据
	 */
	@Query( "select c from ChanceDeliveryTemp c where ( c.saleChance.user.saleArea.id in (select s.saleArea.id from SectionArea s where s.section.id=?1 )) and isReceived = 0"
			+ "and c.saleChance.closeReason = null")
	Page<ChanceDeliveryTemp> getSectionChanceDeliverys(String sectionId,Pageable pageable);
	
	@Query("select r from Role r where r.name=?1")
	Role findByName(String rolename);
	
	
	
}
